package zx.x.modules.sys.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zx.x.common.utils.R;
import zx.x.modules.app.dto.OrderEvaluationDto;
import zx.x.modules.app.entity.OrderEvaluationEntity;
import zx.x.modules.app.service.OrderEvaluationService;
import zx.x.modules.app.vo.OrderEvaluationVo;

import java.util.Arrays;
import java.util.List;


/**
 * 评价
 *
 * @author x
 * @email x
 * @date 2022-12-17 19:39:40
 */
@RestController
@RequestMapping("/sys/orderevaluation")
public class SysOrderEvaluationController {
    @Autowired
    private OrderEvaluationService orderEvaluationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(OrderEvaluationDto dto){
        Page page = PageHelper.startPage(dto.getPage(),dto.getLimit());
        List< OrderEvaluationVo> list = orderEvaluationService.selectList(dto);
        return R.ok().put("page", list).put("pages",page.getPages()).put("total",page.getTotal());
    }

    /**
     * 列表根据用户id
     */
    @RequestMapping("/queryEvaluationByUserId")
    public R queryEvaluationByUserId(OrderEvaluationEntity dto){
        Page page = PageHelper.startPage(dto.getPage(),dto.getLimit());
        List< OrderEvaluationVo> list = orderEvaluationService.queryEvaluationByUserId(dto);
        return R.ok().put("page", list).put("pages",page.getPages()).put("total",page.getTotal());
    }


    /**
     * 打分和
     */
    @RequestMapping("/dfzh")
    public R dfzh(OrderEvaluationEntity dto){
        OrderEvaluationVo vo = orderEvaluationService.dfzh(dto);
        if (vo != null){
            vo.setZf((vo.getWsdfSum()+vo.getFwdfSum()+vo.getWzdfSum()+vo.getSsdfSum())/4);
        }
        return R.ok().put("data", vo);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        OrderEvaluationEntity orderEvaluation = orderEvaluationService.getById(id);
        return R.ok().put("orderEvaluation", orderEvaluation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(OrderEvaluationVo orderEvaluation){
        orderEvaluationService.save(orderEvaluation);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderEvaluationEntity orderEvaluation){
        orderEvaluationService.updateById(orderEvaluation);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        orderEvaluationService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
